﻿using System;
using System.Drawing;
using System.Reflection;
using DevExpress.XtraBars;
using Moonlite.ExtensionApi.XimlInterfaces;

namespace Moonlite.Platform.Ximl {
    public sealed class MenuService : IMenuService {
        public bool ShowContextMenu(Assembly assembly, string guid, int x, int y) {
            return ShowContextMenu(assembly, guid, new Point(x, y));
        }
        public bool ShowContextMenu(Assembly assembly, string guid, Point location) {
            IObject @object = XimlTree.Instance.ObjectManager.GetObject(new Guid(guid), assembly);
            if (@object == null) {
                return false;
            }
            if (!(@object is ContextMenuObject)) {
                return false;
            }
            ContextMenuObject contextMenu = (ContextMenuObject)@object;
            contextMenu.Menu.ShowPopup(location);
            return true;
        }
    }
}
